package gjtx4;


import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Difference2 {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        List<String> list1=new Vector<>();
        long b=System.nanoTime();
        for (int i=0;i<100000;i++){
            list.add("abc");
        }
        long c=System.nanoTime()-b;
        System.out.println("ArrayList加入时间"+c+"纳秒。");
        for (int i=1;i<=100;i++){
            list.remove(((int)Math.random()*list.size()));
        }
        long d=System.nanoTime()-c-b;
        System.out.println("ArrayList删除时间"+d+"纳秒。");
        long b1=System.nanoTime();
        for (int i=0;i<100000;i++){
            list1.add("abc");
        }
        long c1=System.nanoTime()-b1;
        System.out.println("Vector加入时间"+c1+"纳秒。");
        for (int i=1;i<=100;i++){
            list1.remove(((int)Math.random()*list1.size()));
        }
        long d1=System.nanoTime()-c1-b1;
        System.out.println("Vector删除时间"+d1+"纳秒。");
        System.out.println("加入时间比较：");
        if (c>c1){
            System.out.println("Vector快！！");
        }else {
            System.out.println("ArrayList快！！");
        }
        System.out.println("删除时间比较：");
        if (d>d1){
            System.out.println("Vector快！！");
        }else {
            System.out.println("ArrayList快！！");
        }

    }
}
